<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:th="http://www.thymeleaf.org"  xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<meta charset="utf-8"><head th:include="centre/manage/include :: header"></head>
<link rel="stylesheet" type="text/css" href="/css/plugins/layui/layui.css"/>
<link href="/css/jquery-select/jquery.searchableSelect.css" rel="stylesheet" type="text/css">
<style>
    .province {
        float: left;
        position: relative;
        width: 150px;
        height: 35px;
        line-height: 35px;
        border: 1px solid #fff;

    }

    .province:hover {
        border: 1px solid #f7e4a5;
        border-bottom: 1px solid #fffec6;
        background: #fffec6;
    }

    .province .cityall {
        margin-top: 10px;
    }

    .province ul {
        list-style: outside none none;
        position: absolute;
        padding: 0;
        background: #fffec6;
        border: 1px solid #f7e4a5;
        display: none;
        width: auto;
        width: 300px;
        z-index: 999999;
        left: -26px;
        top: 33px;
    }

    .province ul li {
        float: left;
        min-width: 60px;
        margin-left: 20px;
        height: 30px;
        line-height: 30px;
    }

    .province .checkbox-inline {
        padding-top: 0;
    }

    h3, h4, h5 {
        margin: 5px 0;
        font-weight: 600;
    }

    input[type=email], input[type=url], input[type=search], input[type=tel],
    input[type=color], input[type=text], input[type=password], input[type=datetime],
    input[type=datetime-local], input[type=date], input[type=month], input[type=time],
    input[type=week], input[type=number], textarea {
        border-radius: 0 !important;
        color: #858585;
        background-color: #FFF;
        border: 1px solid #D5D5D5;
        padding: 5px 4px 6px;
        font-size: 14px;
        font-family: inherit;
        -webkit-box-shadow: none !important;
        box-shadow: none !important;
        -webkit-transition-duration: .1s;
        transition-duration: .1s;
    }

    .spectable td, .spectable th {
        border: 1px solid #ccc;
        vertical-align: middle;
        text-align: center;
    }

    .spectable th {
        font-weight: bold;
    }

    .spectableinput {
        text-align: center;
    }

    .f {
        border-color: #b94a48;
        -webkit-box-shadow: inset 0 1px 1px rgba(0, 0, 0, 0.075);
        -moz-box-shadow: inset 0 1px 1px rgba(0, 0, 0, 0.075);
        box-shadow: inset 0 1px 1px rgba(0, 0, 0, 0.075);
    }

    .table.table-bordered tr th, .table.table-bordered tr td {
        overflow: hidden;
        text-overflow: ellipsis;
    }

    select {
        padding: 3px 4px;
        height: 30px;
    }
    /* .tags {
        display: inline-block;
        padding: 4px 6px;
        color: #777;
        vertical-align: middle;
        background-color: #FFF;
        border: 1px solid #D5D5D5;
        width: 206px;
    } */
</style>


<body class="gray-bg">
<div class="wrapper wrapper-content">
    <div class="row">
        <div class="col-sm-12">
            <!--			<form class="form-horizontal m-t" id="signupForm">-->
            <div class="form-horizontal m-t">
                <div class="form-group">
                    <ul class="nav nav-arrow-next nav-tabs" id="myTab">
                        <li class="active"><a href="#tab_basic">拼团设置</a></li>
                        <li style="display: none" id="tickeTab"><a href="#ticke_des">优惠券设置</a></li>
                        <li><a href="#tab_des">商品设置</a></li>
                        <li><a href="#tab_des2">商品描述</a></li>
                    </ul>
                </div>
                <div class="tab-content" style="border: 0px;">
                    <div class="tab-pane active" id="tab_basic">
                        <div class="form-group">
                            <label class="col-sm-2 control-label">拼团名称:</label>
                            <div class="col-sm-6">
                                <input id="activityName" name="activityName" placeholder="必填：拼团名称"
                                       class="form-control" type="text" maxlength="100">
                            </div>
                            <label class="col-sm-2 control-label"
                                   style="text-align: left;color:red;">*拼团名称(50个汉字以内)</label>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-2 control-label">开始时间:</label>
                            <div class="col-sm-6">
                                <input type="text" class=" form-control"
                                       id="startTime" name="startTime" placeholder="开始时间"
                                       onclick="laydate({istime: true, format: 'YYYY-MM-DD hh:mm:ss'})"
                                       style="background-color: #fff;" readonly="readonly"/>
                            </div>
                            <label class="col-sm-2 control-label" style="text-align: left;color:red;">*开始时间</label>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-2 control-label">结束时间:</label>
                            <div class="col-sm-6">
                                <input type="text" class=" form-control"
                                       id="endTime" name="endTime" placeholder="结束时间"
                                       onclick="laydate({istime: true, format: 'YYYY-MM-DD hh:mm:ss'})"
                                       style="background-color: #fff;" readonly="readonly"/>
                            </div>
                            <label class="col-sm-2 control-label" style="text-align: left;color:red;">*结束时间</label>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-2 control-label">参团人数:</label>
                            <div class="col-sm-6">
                                <input type="number" class=" form-control"
                                       id="needJoinGroupNum" name="needJoinGroupNum" placeholder="参团人数"
                                       style="background-color: #fff;"/>
                            </div>
                            <label class="col-sm-2 control-label" style="text-align: left;color:red;">*参团人数</label>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-2 control-label">限购数量:</label>
                            <div class="col-sm-6">
                                <input type="number" class=" form-control"
                                       id="purchasingCount" name="purchasingCount" placeholder="限购数量"/>
                            </div>
                            <!--                            <label class="col-sm-2 control-label" style="text-align: left;color:red;">*限购数量</label>-->
                        </div>
                        <div class="form-group">
                            <label class="col-sm-2 control-label">一级推荐人分佣:</label>
                            <div class="col-sm-6">
                                <input type="number" class=" form-control"
                                       id="oneCommission" name="oneCommission" placeholder="一级推荐人分佣"/>
                            </div>
                            <div class="col-sm-2">
                                <em>%</em>
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-2 control-label">二级推荐人分佣:</label>
                            <div class="col-sm-6">
                                <input type="number" class=" form-control"
                                       id="twoCommission" name="twoCommission" placeholder="二级推荐人分佣"/>
                            </div>
                            <div class="col-sm-2">
                                <em>%</em>
                            </div>
                        </div>

                        <div class="form-group">
                            <label class="col-sm-2 control-label">创客拼团发起人分佣:</label>
                            <div class="col-sm-6">
                                <input type="number" class=" form-control"
                                       id="initiatorCommission" name="initiatorCommission" placeholder="创客拼团发起人分佣"/>
                            </div>
                            <div class="col-sm-2">
                                <em>%</em>
                            </div>
                        </div>

                        <div class="form-group">
                            <label class="col-sm-2 control-label">普通会员拼团发起人分佣:</label>
                            <div class="col-sm-6">
                                <input type="number" class=" form-control"
                                       id="generalMemberCommission" name="generalMemberCommission" placeholder="普通会员拼团发起人分佣"/>
                            </div>
                            <div class="col-sm-2">
                                <em>%</em>
                            </div>
                        </div>

                        <div class="form-group" th:if="${ytMallFlag}">
                            <label class="col-sm-2  control-label"> <em class="gg-star"
                                                                        style="margin-right: 7px">*</em>拼团类型：
                            </label>
                            <div class="col-sm-10" style="padding-top: 5px;">
                                <label for="type1" class="radio-inline">
                                    <input type="radio" onclick='radioIsChecked2()'
                                           name="marketingGroupType" value="0" id="marketingGroupType1"
                                           checked="checked"/> 普通拼团
                                </label> &nbsp;&nbsp;&nbsp;
                                <label for="type2" class="radio-inline" th:if="${teamId == null}">
                                    <input type="radio" onclick='radioIsChecked2()' name="marketingGroupType"
                                           value="1" id="marketingGroupType2"/> 大礼包拼团</label>
                            </div>
                        </div>

                        <div class="form-group">
                            <label class="col-sm-2  control-label"> <em class="gg-star"
                                                                        style="margin-right: 7px">*</em>团购类型：
                            </label>
                            <div class="col-sm-10" style="padding-top: 5px;">
                                <label for="type1" class="radio-inline">
                                    <input type="radio" onclick='radioIsChecked()'
                                           name="type" value="0" id="type1" checked="checked"/> 普通
                                </label> &nbsp;&nbsp;&nbsp;
                                <label for="type2" class="radio-inline">
                                    <input type="radio" onclick='radioIsChecked()' name="type"
                                           value="1" id="type2"/> 盲拼</label>
                            </div>
                        </div>

                        <div id="snap" style="display: none">
                            <div class="form-group">
                                <label class="col-sm-2 control-label"><em class="gg-star"
                                                                          style="margin-right: 7px">*</em>赠送类型:</label>
                                <div class="col-sm-10">
                                    <!--<label for="iszhicai" class="checkbox-inline">-->
                                    <!--<input type="checkbox" name="iszhicai" value="1" id="iszhicai"/> 直采-->
                                    <!--</label>-->
                                    <label class="checkbox-inline">
                                        <input type="checkbox" name="isCoupons" value="1" id="isCoupons"
                                               onchange="couponsChange()"/> 优惠券
                                    </label>
                                    <label class="checkbox-inline">
                                        <input type="checkbox" name="isBalance" value="1" id="isBalance"
                                               onchange="balanceChange()"/> 余额
                                    </label>
                                    <label class="checkbox-inline">
                                        <input type="checkbox" name="isIntegral" value="1" id="isIntegral"
                                               onchange="integralChange()"/> 积分
                                    </label>
                                </div>
                            </div>

                            <div class="form-group" id="winningNumberDis" style="display: none">
                                <label class="col-sm-2 control-label"><em class="gg-star"
                                                                          style="margin-right: 7px">*</em>抢购中奖人数:</label>
                                <div class="col-sm-6">
                                    <input type="number" class=" form-control"
                                           id="winningNumber" name="winningNumber" placeholder="抢购中奖人数"
                                           style="background-color: #fff;"/>
                                </div>
                                <label class="col-sm-2 control-label"
                                       style="text-align: left;color:red;">*抢购参团中奖人数</label>
                            </div>

                            <div class="form-group" id="moneyCheck" style="display: none">
                                <label class="col-sm-2 control-label"><em class="gg-star"
                                                                          style="margin-right: 7px">*</em>赠送的余额:</label>
                                <div class="col-sm-6">
                                    <input type="number" class=" form-control"
                                           id="money" name="money" placeholder="赠送的余额"
                                           style="background-color: #fff;"/>
                                </div>
                                <label class="col-sm-2 control-label"
                                       style="text-align: left;color:red;">*抢购参团失败赠送的余额红包</label>
                            </div>
                            <div class="form-group" id="integralCheck" style="display: none">
                                <label class="col-sm-2 control-label"><em class="gg-star"
                                                                          style="margin-right: 7px">*</em>赠送的积分:</label>
                                <div class="col-sm-6">
                                    <input type="number" class=" form-control"
                                           id="integral" name="integral" placeholder="赠送的积分"
                                           style="background-color: #fff;"/>
                                </div>
                                <label class="col-sm-2 control-label"
                                       style="text-align: left;color:red;">*抢购参团失败赠送的积分</label>
                            </div>
                        </div>

                        <div class="form-group">
                            <label class="col-sm-2  control-label"> <em class="gg-star"
                                                                        style="margin-right: 7px">*</em>是否为你推荐：
                            </label>
                            <div class="col-sm-10" style="padding-top: 5px;">
                                <label for="type1" class="radio-inline">
                                    <input type="radio"
                                           name="is_recommend" value="0" id="is_recommend"
                                           checked="checked"/> 否 </label> &nbsp;&nbsp;&nbsp;
                                <label for="type2" class="radio-inline">
                                    <input type="radio" name="is_recommend"
                                           value="1" id="is_recommend2"/> 是</label>
                            </div>
                        </div>

                        <!--						<div class="form-group">-->
                        <!--							<label class="col-sm-2 control-label">适用店铺:</label>-->
                        <!--							<div class="col-sm-6">-->
                        <!--							<input id="centreId" name="centreId"  type="hidden">-->
                        <!--							<input id="centreName" name="centreName" placeholder="点击选择店铺"-->
                        <!--								   class="form-control" type="text" readonly-->
                        <!--								   onclick="chooseCentre()">-->
                        <!--							</div>-->
                        <!--							<label class="col-sm-2 control-label" style="text-align: left;color:red;">*店铺</label>-->
                        <!--						</div>-->
                        <!--						<div class="form-group">-->
                        <!--							<label class="col-sm-2 control-label">每人限购:</label>-->
                        <!--							<div class="col-sm-2">-->
                        <!--								<input id="specTitle" type="number" name="specTitle" class="form-control">-->
                        <!--							</div>-->
                        <!--							<label class="col-sm-2 control-label" style="text-align: left;color:red;">每人可以购买</label>-->
                        <!--						</div>-->
                        <!--						<div class="form-group">-->
                        <!--							<label class="col-sm-2 control-label">订单取消:</label>-->
                        <!--							<div class="col-sm-2" style="padding-top: 7px;width: 6rem;">买家</div>-->
                        <!--							<div class="col-sm-2" style="    padding: 0;">-->
                        <!--								<input id="manudate"  type="number"  name="manudate" class="form-control">-->
                        <!--							</div>-->
                        <!--							<div class="col-sm-4" style="padding-top: 7px;">分钟后未支付订单，订单取消</div>-->
                        <!--						</div>-->

                        <div class="form-group text-center">
                           <!-- <div class="col-sm-8 col-sm-offset-2">
                                <button class="btn btn-primary" onclick="nextStep()">
                                    <i class="fa fa-check"></i>下一步
                                </button>
                            </div>-->
                        </div>
                    </div>

                    <!-- 优惠券选择开始 -->
                    <div class="tab-pane" id="ticke_des">
                        <div class="tab-content" style="border: 0px;">
                            <div class="row">
                                <div id="packageEnd" class="col-sm-6 col-md-4" onclick="addPackage()">
                                    <div class="thumbnailImg">
                                        <span class="glyphicon glyphicon-plus-sign" aria-hidden="true"
                                              style="font-size:100px;"></span>
                                    </div>
                                </div>
                            </div>
                        </div>
                        <div class="form-group text-center">
                           <!-- <div class="col-sm-8 col-sm-offset-2">
                                <button class="btn btn-primary" onclick="nextStep2()">
                                    <i class="fa fa-check"></i>下一步
                                </button>
                            </div>-->
                        </div>
                    </div>

                    <div class="tab-pane" id="tab_des">
                        <!-- 商品选择开始 -->
                        <div id = "groupProduct">
                            &nbsp;
                            <div class="form-group good-choose">
                                <div class="col-md-12">选择商品（只能添加一件商品参加活动)</div>
                                <input type="hidden" id="groupPrice">
                                <!--										<input type="hidden" id="stock">-->
                                <div class="col-md-12 col-xs-6" id="addGoods">
                                    <a class="click-font-color"  onclick="chooseProduct()">选择商品</a>
                                </div>
                            </div>
                            <div class="form-group">
                                <div id="goodsInfo">

                                </div>
                            </div>
                        </div>



                        <!-- 大礼包选择开始 -->
                        <div id = "giftBag" th:if="${ytMallFlag && teamId == null}" style="display: none">
                            &nbsp;
                            <div class="form-group good-choose">
                                <div class="col-md-12">选择大礼包（只能添加一件大礼包参加活动)</div>
                                <input type="hidden" id="giftBagPrice">
                                <!--										<input type="hidden" id="stock">-->
                                <div class="col-md-12 col-xs-6" id="addGiftBag">
                                    <a onclick="chooseGiftBag()">选择大礼包</a>
                                </div>
                            </div>
                            <div class="form-group">
                                <div id="giftBagInfo">

                                </div>
                            </div>
                        </div>
                    </div>
                    <!-- 商品描述部分 开始 -->
                    <div class="tab-pane" id="tab_des2" style="height: 550px;">
                        <div class="form-group">
                            <label class="col-sm-2 control-label no-padding-right" for="form-field-1">商品详情</label>
                            <div class="col-sm-10">
                                <textarea id="content" name="content" style="height: 500px;"></textarea>
                            </div>
                        </div>
                    </div>
                    <!-- 商品描述部分 结束-->
                </div>
                <div class="form-group text-center">
                    <div class="col-sm-8 col-sm-offset-2">
                        <!--														<button type="submit" class="btn btn-primary"><i class="fa fa-check"></i>提交</button>-->
                        <button class="btn btn-primary" onclick="saveProduct()">
                            <i class="fa fa-check"></i>提交
                        </button>
                        <!--														<div class="btn btn-danger" onclick="reset()">-->
                        <!--															<i class="fa fa-remove"></i> 重置-->
                        <!--														</div>-->
                    </div>
                </div>
                <div id="goodsSeckillPrice" style="display:none;    margin-top: 1rem;">
                    <!--                    <div>-->
                    <!--                        <label class="col-sm-4">拼团价格:</label>-->
                    <!--                        <div class="col-sm-8">-->
                    <!--                            <input id="seckillPrice" name="displayorder" placeholder="必填：拼团价格"-->
                    <!--                                   class="form-control" type="number" value="0">-->
                    <!--                        </div>-->
                    <!--                    </div>-->
                    <!--                    <div>-->
                    <!--                        <label class="col-sm-4">活动库存:</label>-->
                    <!--                        <div class="col-sm-8">-->
                    <!--                            <input type="number"-->
                    <!--                                   id="seckillStotal" name="seckillStotal" placeholder="必填:活动库存"/>-->
                    <!--                        </div>-->

                    <!--                    </div>-->

                    <form class="form-horizontal" style="margin-top: 15px">
                        <div class="form-group">
                            <label class="col-sm-5 control-label">拼团价格:</label>
                            <div class="col-sm-6">
                                <input id="seckillPrice" name="displayorder"
                                       type="number" class="form-control" value="0" placeholder="必填:拼团价格"/>
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-5 control-label">vip拼团价格:</label>
                            <div class="col-sm-6">
                                <input id="vipPrice" name="vipPrice"
                                       type="number" class="form-control" value="0" placeholder="vip拼团价格"/>
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-5 control-label">活动库存:</label>
                            <div class="col-sm-6">
                                <input id="seckillStotal" name="seckillStotal"
                                       type="number" class="form-control" placeholder="必填:活动库存"/>
                            </div>
                        </div>
                    </form>
                </div>

            </div>
            <!--			</form>-->
        </div>
    </div>
</div>

<div th:include="centre/manage/include::footer"></div>
<script type="text/javascript" src="/js/ueditor/ueditor.config.js"></script>
<script type="text/javascript" src="/js/ueditor/ueditor.all.min.js"></script>
<script type="text/javascript" src="/js/ueditor/lang/zh-cn/zh-cn.js"></script>
<script type="text/javascript" src="/js/ueditor/custom.js?v=2"></script>
<script type="text/javascript" src="/js/appjs/product/AreaData.js"></script>
<script type="text/javascript" src="/public/ace/js/ace-extra.js"></script>
<script type="text/javascript" src="/js/plugins/layui/layui.js"></script>
<script type="text/javascript" src="/js/plugins/layer/layer.js"></script>
<script type="text/javascript" src="/js/bootstrap.min.js"></script>
<script src="/js/jquery-select/jquery.searchableSelect.js"></script>
<script type="text/javascript">

    var prefix = "/marketing/manage";

    $(function () {
        // tab切换
        $('#myTab a').click(function (e) {
            e.preventDefault();
            $('#myTab li').each(function () {
                $(this).removeClass('active')
            })
            $('.tab-content .tab-pane').each(function () {
                $(this).removeClass('active')
            })
            $(this).parent().addClass('active')
            id = $(this).attr('href')
            $(id).addClass('active');
        })
    })

    UE.registerUI('uploadImage', function (editor, uiName) {
        return new UE.ui.Button({
            name: '上传图片',
            title: '上传图片',
            cssRules: 'background-position:-380px 0',
            onclick: function () {
                layer.open({
                    id: 'selectImgs',
                    type: 2,
                    title: '批量选择图片',
                    maxmin: true,
                    shadeClose: false,
                    area: ['60%', '70%'],
                    content: '/platform/config/batchUploadImgUeditor'  // iframe的url
                });
            }
        });
    });

    // 加载图片进ueditor中
    function loadImgsToUeditor(result) {
        if (!result || result.length < 1) {
            layer.msg(result.msg, {icon: 7});
            return;
        }
        console.info(result);
        /* var imgUrlArray = result.split(","); */
        let editor = UE.getEditor('content');
        for (var i = 0; i < result.length; i++) {
            var imgUrl = result[i];
            editor.execCommand('inserthtml', `<img src=${imgUrl}>`);
        }
    }


    var ue = UE.getEditor('content');
    $('#content').data('editor', ue);
    $('#content').parents('form').submit(function () {
        if (ue.queryCommandState('source')) {
            ue.execCommand('source');
        }
    });

    function closeDow() {
        var index = parent.layer.getFrameIndex(window.name); // 获取窗口索引
        parent.layer.close(index);
    }

    layui.use('laydate', function () {
        var laydate = layui.laydate;
        laydate.render({
            elem: '#timestart', type: 'datetime'
        });

        laydate.render({
            elem: '#timeend', type: 'datetime'
        });

        laydate.render({
            elem: '#upStartTime', type: 'datetime'
        });

        laydate.render({
            elem: '#upEndTime', type: 'datetime'
        });


    })

    function nextStep() {
        if ($("#tickeTab").css("display") === 'none') {
            $('#myTab a[href="#tab_des"]').trigger("click");
        } else {
            $('#myTab a[href="#ticke_des"]').trigger("click");
        }

    }

    function nextStep2() {
        $('#myTab a[href="#tab_des"]').trigger("click");
    }

    /**
     * 选择商品
     */
    function chooseProduct() {

        // iframe层
        layer.open({
            id: 'group_add',
            type: 2,
            title: '选择商品',
            maxmin: true,
            shadeClose: false, // 点击遮罩关闭层
            area: ['90%', '90%'],
            content: prefix + '/toChooseProduct' // iframe的url
        });
    }

    /**
     * 选择商家
     */
    function chooseCentre() {

        // iframe层
        layer.open({
            id: 'choose_centre',
            type: 2,
            title: '选择店铺',
            maxmin: true,
            shadeClose: false, // 点击遮罩关闭层
            area: ['70%', '80%'],
            content: "/centre/manage/chooseCentre" // iframe的url
        });
    }

    function checkoption() {
        var full = true;
        if ($("#hasoption").get(0).checked) {
            $(".spec_title").each(function (i) {
                if ($(this).val() == '' || $(this).val() == undefined) {
                    layer.alert("请输入规格名称!", {icon: 5});
                    full = false;
                    return false;
                }
            });
            $(".spec_item_title").each(function (i) {
                if ($(this).val() == '' || $(this).val() == undefined) {
                    layer.alert("请输入规格项名称!", {icon: 5});
                    full = false;
                    return false;
                }
            });
        }
        if (!full) {
            return false;
        }
        return full;
    }

    var row = {};

    function chooseProductCallback(row) {

        var html = '<a class="goods-thumb" href="' + row.thumb + '" target="_blank" rel="noopener noreferrer" style="background-image: url(' + row.thumb + ');"></a>';
        html = html + '<div class="goods-control"><div class="goods-info"><div class="goods-actions"><a class="opt click-font-color" onclick="editProduct()">编辑</a>&nbsp;&nbsp;<a class="opt click-font-color" onclick="deleteProduct()">删除</a></div></div>';
        html = html + '<h3 class="goods-title">' + row.title + '</h3>';
        html = html + '<span class="seckill-price">团购价：未设置</span><input type="hidden" id="groupPrice">';
        html = html + '<span class="seckill-vipPrice">vip团购价：未设置</span><input type="hidden" id="vipGroupPrice">';
        html = html + '<span class="seckill-stock">库存：未设置</span><input type="hidden" id="stock">';
        html = html + '<p class="zent-form__help-desc">点击“编辑“修改商品的团购价</p></div>';

        this.row = row;
        console.info(row);
        $("#goodsInfo").append(html);
        $("#addGoods").hide();
        if (row.hasoption == 1) {//有规格，展示规格
            showSeckillPriceStock(row.id);
        } else {//没有规格，展示价格
            showSeckillPrice();
        }
    }

    function editProduct() {
        if (this.row.hasoption == 1) {
            showSeckillPriceStock(this.row.id);
        } else {
            showSeckillPrice();
        }
    }

    function editGiftBag() {
        showGiftBag();
    }

    function showGiftBag() {
        if (this.row) {
            $("#seckillPrice").val(this.row.activityPrice);
            $("#vipPrice").val(this.row.activityPrice)
            $("#seckillStotal").val(this.row.stock);
        }
        layer.open({
            type: 1,
            title: false,
            closeBtn: 0,
            area: ['auto'],
            shadeClose: false,
            content: $("#goodsSeckillPrice"),
            btn: ['确定', '取消'],
            yes: function (index, layero) {

                $(".seckill-price").text("拼团价: " + $("#seckillPrice").val())
                $(".seckill-vipPrice").text("vip拼团价: " + $("#vipPrice").val())
                $(".seckill-stock").text("库存: " + $("#seckillStotal").val());
                $("#groupPrice").val($("#seckillPrice").val());
                $("#vipGroupPrice").val($("#vipPrice").val());
                $("#stock").val($("#seckillStotal").val());

                layer.close(index);
            }
            , cancel: function () {
                //右上角关闭回调
                return true;// 开启该代码可禁止点击该按钮关闭
            }
        });

    }

    function chooseCentreCallback(row) {
        console.log(row);
        $("#centreId").val(row.centreId);
        $("#centreName").val(row.shortName);
    }

    function deleteProduct() {
        $("#goodsInfo").empty();
        $("#addGoods").show();
        $("#giftBagInfo").empty();
        $("#addGiftBag").show();
        localStorage.removeItem("productSKU");
    }

    function showSeckillPrice() {
        if (this.row) {
            $("#seckillPrice").val(this.row.marketprice);
            $("#vipPrice").val(this.row.marketprice)
            $("#seckillStotal").val(this.row.total);
        }
        layer.open({
            type: 1,
            title: false,
            closeBtn: 0,
            area: ['auto'],
            shadeClose: false,
            content: $("#goodsSeckillPrice"),
            btn: ['确定', '取消'],
            yes: function (index, layero) {

                $(".seckill-price").text("拼团价: " + $("#seckillPrice").val())
                $(".seckill-vipPrice").text("vip拼团价: " + $("#vipPrice").val())
                $(".seckill-stock").text("库存: " + $("#seckillStotal").val());
                $("#groupPrice").val($("#seckillPrice").val());
                $("#vipGroupPrice").val($("#vipPrice").val());
                $("#stock").val($("#seckillStotal").val());

                layer.close(index);
            }
            , cancel: function () {
                //右上角关闭回调
                return true;// 开启该代码可禁止点击该按钮关闭
            }
        });

    }


    /**
     * 选择sku 设置类型
     */
    var index = 0;

    function showSeckillPriceStock(id) {

        index = layer.open({
            type: 2,
            title: '设置团购价格和库存',
            closeBtn: 0,
            area: ['100%', '100%'],
            shadeClose: false,
            content: prefix + '/toProductGroupStockSetting?productCentreId=' + id
        });

    }

    function callBack(data) {

        console.info(data);
        var minPrice = 0;
        var maxPrice = 0;
        var stock = 0;
        for (var i = 0; i < data.length; i++) {
            var groupPrice = data[i].groupPrice;
            var vipPrice = data[i].vipPrice;
            if (i == 0) {
                minPrice = groupPrice
                maxPrice = vipPrice
            }
            stock = Number(stock) + Number(data[i].stock);
        }
        $(".seckill-price").text("团购价: " + "￥" + minPrice);
        $(".seckill-vipPrice").text("vip团购价: " + "￥" + maxPrice);
        $(".seckill-stock").text("库存: " + stock);

        $("#groupPrice").val(minPrice);
        $("#vipGroupPrice").val(maxPrice);
        $("#vipPrice").val(maxPrice);
        $("#stock").val(stock);


        if (data.length > 0) {
            localStorage.setItem("productSKU", JSON.stringify(data));
        }

    }

    function callClose() {
        layer.close(index);
    }

    $.validator.setDefaults({
        submitHandler: function () {
            saveProduct();
        }
    });

    function validateRule() {
        var icon = "<i class='fa fa-times-circle'></i> ";
        $("#signupForm").validate({
            rules: {
                activityName: {
                    required: true
                },
                startTime: {
                    required: true
                },
                endTime: {
                    required: true
                }
            },
            messages: {
                activityName: {
                    required: icon + "活动名称不能为空"
                },
                startTime: {
                    required: icon + "开始时间不能为空"
                },
                endTime: {
                    required: icon + "结束时间不能为空"
                }
            }
        })
    }


    function saveProduct() {
        var sku = localStorage.getItem("productSKU");

        var activityName = $("#activityName").val();
        if (!activityName) {

            layer.tips("活动名称不能为空", '#activityName', {time: 2000, tips: 2});

            $("#activityName").focus();
            return;
        }
        var startTime = $("#startTime").val();
        if (!startTime) {
            layer.tips("开始时间不能为空", '#startTime', {time: 2000, tips: 2});

            $("#startTime").focus();
            return;
        }
        var endTime = $("#endTime").val();

        if (!endTime) {
            layer.tips("结束时间不能为空", '#endTime', {time: 2000, tips: 2});
            toastr.error("结束时间不能为空");
            $("#endTime").focus();
            return;
        }

        var endTime = $("#endTime").val();

        var productId = this.row.id;

        var centreId = this.row.centreId;
        var teamId = this.row.liansuoid?this.row.liansuoid:this.row.teamId;

        var productName = this.row.title?this.row.title:this.row.activityName;
        var thumb = this.row.thumb;

        var groupPrice = $("#groupPrice").val();
        if(!groupPrice){
            layer.tips("未设置商品!",'#groupPrice',{time:2000,tips:2});
            toastr.error("未设置商品!");
            $("#groupPrice").focus();
            return ;
        }
        var description = UE.getEditor('content').getContent();
        var vipPrice = $("#vipGroupPrice").val();

        var stock = $("#stock").val();
        if(!stock){
            layer.tips("库存不能为空!",'#stock',{time:2000,tips:2});
            toastr.error("库存不能为空!");
            $("#stock").focus();
            return ;
        }
        if(stock<0){
            layer.tips("库存不能为负!",'#stock',{time:2000,tips:2});
            toastr.error("库存不能为负!");
            $("#stock").focus();
            return ;
        }

        var needJoinGroupNum = $("#needJoinGroupNum").val();
        var purchasingCount = $("#purchasingCount").val();

        var oneCommission = $("#oneCommission").val();
        var twoCommission = $("#twoCommission").val();
        var initiatorCommission = $("#initiatorCommission").val();
        var generalMemberCommission = $("#generalMemberCommission").val();


        var type = $("input[name='type']:checked").val();
        var marketingGroupType = $("input[name='marketingGroupType']:checked").val();

        var winningNumber = $("#winningNumber").val();
        var money = $("#money").val();
        var integral = $("#integral").val();

        var coupons = $("input[name='isCoupons']:checked").val();
        var balance = $("input[name='isBalance']:checked").val();
        var integralGroup = $("input[name='isIntegral']:checked").val();

        if (type == 1) {
            if (!winningNumber) {
                layer.tips("请填写抢购中奖人数", '#minPrice', {time: 2000, tips: 2});
                return;
            }
        }

        var typeArry = [];
        if (coupons == 1) {
            typeArry.push(coupons);
        }
        if (balance == 1) {
            typeArry.push(balance);
            if (!money) {
                layer.tips("请填写赠送余额", '#minPrice', {time: 2000, tips: 2});
                return;
            }
        }
        if (integralGroup == 1) {
            typeArry.push(integralGroup);
            if (!integral) {
                layer.tips("请填写赠送积分", '#minPrice', {time: 2000, tips: 2});
                return;
            }
        }


        if (!productId) {
            layer.tips("请选择商品", '#minPrice', {time: 2000, tips: 2});
            $('#myTab a[href="#tab_des"]').trigger("click");
            return;
        }
        var is_recommend = $("input[name='is_recommend']:checked").val();

        var data = {
            centreId: centreId,
            teamId: teamId,
            activityName: activityName,
            startTime: startTime,
            endTime: endTime,
            productId: productId,
            productName: productName,
            thumb: thumb,
            groupPrice: groupPrice,
            needJoinGroupNum: needJoinGroupNum || 3,
            stock: stock,
            purchasingCount: purchasingCount,
            oneCommission: oneCommission,
            twoCommission: twoCommission,
            type: type,
            marketingGroupType: marketingGroupType,
            winningNumber: winningNumber,
            money: money,
            integral: integral,
            ticketList: tickeData,
            isCoupons: coupons,
            isBalance: balance,
            isIntegral: integralGroup,
            vipPrice: vipPrice,
            description: description,
            initiatorCommission: initiatorCommission,
            generalMemberCommission: generalMemberCommission,
            isRecommend:is_recommend
        }

        var skuArray = [];
        if (sku) {
            var dataSku = JSON.parse(sku);
            for (var i = 0; i < dataSku.length; i++) {
                var tempSku = dataSku[i];
                var sku = {
                    id: tempSku.id,
                    productCentreId: tempSku.productCentreId,
                    centreId: tempSku.centreId,
                    skuId: tempSku.id,
                    title: tempSku.title,
                    thumb: tempSku.thumb,
                    groupPrice: tempSku.groupPrice,
                    vipPrice: tempSku.vipPrice,
                    specs: tempSku.specs,
                    stock: tempSku.stock
                }
                skuArray.push(sku);
            }
        }

        data.skus = skuArray;

        $.ajax({
            url: '/marketing/manage/group/saveOrUpdate',
            contentType: "application/json",
            dataType: "json",
            type: 'POST',
            data: JSON.stringify(data),
            success: function (result) {
                if (result.code == 0) {
                    layer.alert("保存成功", {icon: 6});
                } else {
                    if (result.msg != "" && result.msg != null) {
                        layer.alert(result.msg, {icon: 5});
                    } else {
                        layer.alert("保存失败，请联系管理员", {icon: 5});
                    }

                }
            }
        })
    }


    function radioIsChecked() {
        if ($("#type2").is(':checked')) {
            $('#snap').show();
            $('#winningNumberDis').show();
        } else {
            $('#snap').hide();
            $('#winningNumberDis').hide();
            $('#winningNumber').val("");

            $('#money').val("");
            $('#integral').val("");
            for (var i = 0; i < tickeData.length; i++) {
                $("#packageDiv" + i).remove();
            }

            tickeData = [];
            packageNum = 0;

            $("input[name='isCoupons']:checked").removeAttr("checked");
            $("input[name='isBalance']:checked").removeAttr("checked");
            $("input[name='isIntegral']:checked").removeAttr("checked");

            $('#tickeTab').hide();
        }
    }

    function couponsChange() {
        var coupons = $("input[name='isCoupons']:checked").val();
        if (coupons == 1) {
            $('#tickeTab').show();
        } else {
            $('#tickeTab').hide();

            for (var i = 0; i < tickeData.length; i++) {
                $("#packageDiv" + i).remove();
            }

            tickeData = [];
            packageNum = 0;
        }
    }

    function balanceChange() {
        var balance = $("input[name='isBalance']:checked").val();
        if (balance == 1) {
            $('#moneyCheck').show();
        } else {
            $('#moneyCheck').hide();
            $('#money').val("");
        }
    }

    function integralChange() {
        var integralGroup = $("input[name='isIntegral']:checked").val();
        if (integralGroup == 1) {
            $('#integralCheck').show();
        } else {
            $('#integralCheck').hide();
            $('#integral').val("");
        }
    }

    /**
     * 选择优惠券
     */
    function chooseCoupon() {
        // iframe层
        layer.open({
            id: 'group_add',
            type: 2,
            title: '选择优惠券',
            maxmin: true,
            shadeClose: false, // 点击遮罩关闭层
            area: ['90%', '90%'],
            content: prefix + '/toChooseCoupon?packageNum=' + packageNum,
            cancel: function () {
                //右上角关闭回调
                reLoadCouponList();
                return true; // 开启该代码可禁止点击该按钮关闭
            }
        });
    }

    function reLoadCouponList() {
        $('#couponListTable').bootstrapTable('refresh');
    }

    var packageNum = 0;

    function addPackage() {
        packageNum++;
        var html = "<div class='col-sm-6 col-md-4' id='packageDiv" + packageNum + "'>\n" +
            "        <input id='packageNum' type='hidden' value='" + packageNum + "'>\n" +
            "        <div class='thumbnail' style='width: 360px;height: 550px;'>\n" +
            "            <img style='border:1px solid #ddd;padding:5px;min-width:95%;min-height:70%;max-width:95%;max-height:70%;'\n" +
            "                 id='tickeThumb" + packageNum + "' src='...'>\n" +
            "                <div class='caption'>\n" +
            "                    <h3 id='tickeName" + packageNum + "'>优惠券名称</h3>\n" +
            "                    <p>优惠券类型:<em id='tickeType" + packageNum + "'></em></p>\n" +
            "                    <p>金额/折扣:<em id='amount" + packageNum + "'></em></p>\n" +
            "                    <p>赠送数量:<em id='count" + packageNum + "'></em></p>\n" +
            "                    <p><a onclick='deleteTicke(" + packageNum + ")' href='###' class='btn btn-primary' role='button'>删除</a> <a onclick='chooseCoupon(" + packageNum + ")' href='###'\n" +
            "                                                                                       class='btn btn-default'\n" +
            "                                                                                       role='button'>选择优惠券</a></p>\n" +
            "                </div>\n" +
            "        </div>\n" +
            "    </input>";
        $("#packageEnd").before(html);
    }

    var tickeData = [];

    function selectTickeCallBack(tickeData, packageNum) {

        var typeName = "";
        if (tickeData.type == 1) {
            typeName = '抵扣券'
        } else if (tickeData.type == 2) {
            typeName = '折扣券'
        } else if (tickeData.type == 3) {
            typeName = '包邮券'
        }

        // //给商品选择框赋值
        $("#tickeThumb" + packageNum).attr("src", tickeData.ticketImg);
        $("#tickeName" + packageNum).html(tickeData.ticketName);
        $("#tickeType" + packageNum).html(typeName);
        $("#amount" + packageNum).html(tickeData.amount);
        $("#count" + packageNum).html(tickeData.count);

        //存储选择的套餐内商品
        this.tickeData[packageNum + ""] = {
            id: tickeData.id,
            count: tickeData.count,
        }
    }

    function deleteTicke(index) {
        $("#packageDiv" + index).remove();
        this.tickeData[index + ""] = null
    }



    /**
     * 选择大礼包
     */
    function chooseGiftBag(){

        // iframe层
        layer.open({
            id: 'gift_bag_add',
            type: 2,
            title: '选择大礼包',
            maxmin: true,
            shadeClose: false, // 点击遮罩关闭层
            area: ['90%', '90%'],
            content: '/activity/manage/toChooseGiftBag' // iframe的url
        });
    }

    function radioIsChecked2() {
        if ($("#marketingGroupType2").is(':checked')) {
            $("#giftBag").show();
            $("#groupProduct").hide();
        } else {
            $("#giftBag").hide();
            $("#groupProduct").show();
        }
    }


    function showGiftBagPrice() {
        if (this.row) {
            $("#seckillPrice").val(this.row.activityPrice);
            $("#vipPrice").val(this.row.activityPrice)
            $("#seckillStotal").val(this.row.stock);
        }
        layer.open({
            type: 1,
            title: false,
            closeBtn: 0,
            area: ['auto'],
            shadeClose: false,
            content: $("#goodsSeckillPrice"),
            btn: ['确定', '取消'],
            yes: function (index, layero) {

                $(".seckill-price").text("拼团价: " + $("#seckillPrice").val())
                $(".seckill-vipPrice").text("vip拼团价: " + $("#vipPrice").val())
                $(".seckill-stock").text("库存: " + $("#seckillStotal").val());
                $("#groupPrice").val($("#seckillPrice").val());
                $("#vipGroupPrice").val($("#vipPrice").val());
                $("#stock").val($("#seckillStotal").val());

                layer.close(index);
            }
            , cancel: function () {
                //右上角关闭回调
                return true;// 开启该代码可禁止点击该按钮关闭
            }
        });

    }

    function chooseGiftBagCallback(row){
        var html = '<a class="goods-thumb" href="' + row.thumb + '" target="_blank" rel="noopener noreferrer" style="background-image: url(' + row.thumb + ');"></a>';
        html = html + '<div class="goods-control"><div class="goods-info"><div class="goods-actions"><a class="opt click-font-color" onclick="showGiftBag()">编辑</a>&nbsp;&nbsp;<a class="opt click-font-color" onclick="deleteProduct()">删除</a></div></div>';
        html = html + '<h3 class="goods-title">' + row.activityName + '</h3>';
        html = html + '<span class="seckill-price">团购价：未设置</span><input type="hidden" id="groupPrice">';
        html = html + '<span class="seckill-vipPrice">vip团购价：未设置</span><input type="hidden" id="vipGroupPrice">';
        html = html + '<span class="seckill-stock">库存：未设置</span><input type="hidden" id="stock">';
        html = html + '<p class="zent-form__help-desc">点击“编辑“修改商品的团购价</p></div>';

        this.row = row;
        $("#giftBagInfo").append(html);
        $("#addGiftBag").hide();
        showGiftBagPrice();
    }
</script>

</body>
</html>
